#include "app_modbus.h"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>


int main(int argc, char const *argv[])
{
    
     int ret=app_modbus_init("/dev/pts/1"); 
     if(ret<0)
     {
         return -1;
     }
     uint8_t coil_value[1]={0x01};
     app_modbus_writeCoil(1, 2, 1,coil_value);

    

     uint8_t coil_buff[1]={0};
     app_modbus_readCoil(1,2,1,coil_buff);
     printf("coil_buff:%d\n",coil_buff[0]);


     // 写保持寄存器  目标角度  最大速度
     uint16_t hold_reg_value[4];
     float target_angle=3600;
     float max_speed=60;
     memcpy(hold_reg_value, &target_angle, sizeof(float));
     memcpy(hold_reg_value+2, &max_speed, sizeof(float));
     app_modbus_writeHoldReg(1, 0, 4,hold_reg_value);

     //读输入寄存器  当前角度  电机状态

     uint16_t input_reg_value[3];
     app_modbus_readInputReg(1, 0, 3,input_reg_value);
     float cur_angle;
     bool motor_status;

     memcpy(&cur_angle, input_reg_value, sizeof(float));
     memcpy(&motor_status, input_reg_value+2, sizeof(bool));

     printf("cur_angle:%f\n",cur_angle);
     printf("motor_status:%d\n",motor_status);

     

    return 0;
}
